using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace WinAuthProxy
{
    /// <summary>
    /// Pagina che ha come compito di individuare l'utente di dominio tramite l'impersonation di windows authentication
    /// </summary>
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string redirectUrl = string.Format("{0}?usr={1}",
                ConfigurationManager.AppSettings["TargetUrl"] ?? string.Empty,
                GetUser());

            Response.Redirect(redirectUrl);

        }
        protected string GetUser()
        {
            string susr = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
            string[] mat = susr.Split('\\');
            if (mat.Length == 0)
                return string.Empty;

            return mat[mat.Length - 1];
        }
    }
}
